package com.test.base.api;

import com.test.base.dao.NideshopBrandDao;
import com.test.base.entity.NideshopBrand;
import com.test.base.utils.Assist;
import com.test.base.utils.PageUtil;
import com.test.base.vo.common.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "api/brand")
@Api(description = "？？？？")
public class BrandApi {
    @Autowired
    private NideshopBrandDao nideshopBrandDao;

    @ApiOperation(value = "???", notes = "")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "query", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "Integer", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true, paramType = "query", dataType = "Integer", defaultValue = "10")
    })
    public ResultData<List<NideshopBrand>> getBrandList(Long userId, Integer page, Integer size) {
        Assist brand = new Assist();
        brand.setStartRow(PageUtil.getStartRow(page, size));
        brand.setRowSize(size);
        brand.setResultColumn("id,name,floor_price,app_list_pic_url");
        List<NideshopBrand> nideshopBrands = nideshopBrandDao.selectNideshopBrand(brand);
        return new ResultData<>(nideshopBrands, null, true);
    }

    @ApiOperation(value = "???详细", notes = "")
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParam(name = "id", value = "id", paramType = "query", required = true, dataType = "Long")
    public ResultData<NideshopBrand> detail(Long id) {
        NideshopBrand nideshopBrand = nideshopBrandDao.selectNideshopBrandById(id);
        return new ResultData<>(nideshopBrand, null, true);
    }
}
